<?php
	$no_klaim = $_POST['no_klaim'];
	$tgl_masuk = $_POST['tgl_masuk'];
	$dokter = $_POST['dokter'];
	$tgl_keluar = $_POST['tgl_keluar'];
	$tgl_klaim = $_POST['tgl_klaim'];
	$id_jaminan = $_POST['id_jaminan'];
	$no_peserta = $_POST['no_peserta'];
	$keterangan = $_POST['keterangan'];
	$jenis_layanan = $_POST['jenis_layanan'];
	$ppk = $_POST['nama_ppk'];
	$umur_pasien = $_POST['umur_pasien'];
	$no_rm = $_POST['no_rm'];
	$verifikator = $_POST['verifikator'];
	$status_keluar = $_POST['status_keluar'];
	$sudah_dibayar = $_POST['sudah_dibayar'];
	$keterangan = $_POST['keterangan'];
	$tgl_skrang=date('Y-m-d');
	
	//akhir klaim
	
	//tab abhp
	$id_abhp = $_POST['id_abhp'];
	$jumlah_abhp = $_POST['jumlah_abhp'];
	$harga_abhp = $_POST['harga_abhp'];
	$harga_abhp_awal = $_POST['harga_abhp_awal'];
	$jumlah_abhp_minta = $_POST['jumlah_abhp_minta'];
	
	//tab diagnosis
	$id_diagnosis = $_POST['id_diagnosis'];
	
	//tab layanan
	$id_layanan = $_POST['id_layanan'];
	$harga_layanan = $_POST['harga_layanan'];
	$harga_layanan_awal = $_POST['harga_layanan_awal'];
	
	//tab obat
	$id_obat = $_POST['id_obat'];
	$jumlah_obat = $_POST['jumlah_obat'];
	$harga_obat = $_POST['harga_obat'];
	$harga_obat_awal = $_POST['harga_obat_awal'];
	$jumlah_obat_minta = $_POST['jumlah_obat_minta'];
	
	//tab prosedur
	$id_prosedur = $_POST['id_prosedur'];
	
	//tab tindakan
	$id_tindakan = $_POST['id_tindakan'];
	$harga_tindakan = $_POST['harga_tindakan'];
	$harga_tindakan_awal = $_POST['harga_tindakan_awal'];
	
	//tab laboratorium
	$id_lab = $_POST['id_lab'];
	$harga_lab = $_POST['harga_lab'];
	$harga_lab_awal = $_POST['harga_lab_awal'];
	
	//tab rehabilitasi
	$id_rehabilitasi = $_POST['id_rehabilitasi'];
	$harga_rehabilitasi = $_POST['harga_rehabilitasi'];
	$harga_rehabilitasi_awal = $_POST['harga_rehabilitasi_awal'];
	
	//tab elektromedik
	$id_elektromedik = $_POST['id_elektromedik'];
	$harga_elektromedik = $_POST['harga_elektromedik'];
	$harga_elektromedik_awal = $_POST['harga_elektromedik_awal'];
	
	//tab radiologi
	$id_radiologi = $_POST['id_radiologi'];
	$harga_radiologi = $_POST['harga_radiologi'];
	$harga_radiologi_awal = $_POST['harga_radiologi_awal'];
	
	//simpan klaim
	$sql_insert_klaim="update klaim set id_ppk='$ppk',id_peserta='$no_peserta',no_rm='$no_rm',id_jaminan='$id_jaminan',
				dokter='$dokter',umur='$umur_pasien',tgl_masuk='$tgl_masuk',tgl_keluar='$tgl_keluar',
				id_status_keluar='$status_keluar',id_jenis_layanan='$jenis_layanan',
				id_verifikator='$verifikator',keterangan='$keterangan' where id_klaim='$no_klaim'";
	//echo $sql_insert_klaim;
	//exit;
	$qry_klaim=mysql_query($sql_insert_klaim);
	
	if($qry_klaim){
		//insert abhp
		if(!empty($id_abhp)){
			$qry_hapus=mysql_query("delete from klaim_abhp where id_klaim='".$no_klaim."'");
		foreach($id_abhp as $key=>$val){
			$sql_abhp="insert into klaim_abhp(id_klaim,id_abhp,jumlah,jumlah_ditanggung,tarif,tarif_ditanggung) 
			values ('$no_klaim','".$val."','".$jumlah_abhp[$key]."','".$jumlah_abhp_minta[$key]."','".$harga_abhp_awal[$key]."','".$harga_abhp[$key]."')";
			$qry_abhp=mysql_query($sql_abhp);
		}
		}
		
		//insert diagnosis
		if(!empty($id_diagnosis)){
		$qry_hapus=mysql_query("delete from klaim_diagnosis where id_klaim='".$no_klaim."'");
		foreach($id_diagnosis as $key=>$val){
			$sql_diagnosis="insert into klaim_diagnosis(id_klaim,icd10) values ('$no_klaim','".$val."')";
			$qry_diagnosis=mysql_query($sql_diagnosis);
		}
		}
		
		//insert layanan
		if(!empty($id_layanan)){
		$qry_hapus=mysql_query("delete from klaim_layanan where id_klaim='".$no_klaim."'");
		foreach($id_layanan as $key=>$val){
			$sql_layanan="insert into klaim_layanan(id_klaim,id_layanan,tarif_ditanggung,tarif) 
				values ('$no_klaim','".$val."','".$harga_layanan[$key]."','".$harga_layanan_awal[$key]."')";
			$qry_layanan=mysql_query($sql_layanan);
		}
		}
		
		//insert obat
		if(!empty($id_obat)){
		$qry_hapus=mysql_query("delete from klaim_obat where id_klaim='".$no_klaim."'");
		foreach($id_obat as $key=>$val){
			$sql_obat="insert into klaim_obat(id_klaim,id_obat,jumlah,jumlah_ditanggung,tarif,tarif_ditanggung) 
				values ('$no_klaim','".$val."','".$jumlah_obat[$key]."','".$jumlah_obat_minta[$key]."','".$harga_obat_awal[$key]."','".$harga_obat[$key]."')";
			$qry_obat=mysql_query($sql_obat);
		}
		}
		
		//insert prosedur
		if(!empty($id_prosedur)){
		$qry_hapus=mysql_query("delete from klaim_prosedur where id_klaim='".$no_klaim."'");
		foreach($id_prosedur as $key=>$val){
			$sql_prosedur="insert into klaim_prosedur(id_klaim,icd9cm) values ('$no_klaim','".$val."')";
			$qry_prosedur=mysql_query($sql_prosedur);
		}
		}
		
		//insert tindakan
		if(!empty($id_tindakan)){
		$qry_hapus=mysql_query("delete from klaim_tindakan where id_klaim='".$no_klaim."'");
		foreach($id_tindakan as $key=>$val){
			$sql_tindakan="insert into klaim_tindakan(id_klaim,id_tindakan,tarif_ditanggung,tarif) 
				values ('$no_klaim','".$val."','".$harga_tindakan[$key]."','".$harga_tindakan_awal[$key]."')";
			$qry_tindakan=mysql_query($sql_tindakan);
		}
		}
		
		//insert laboratorium
		if(!empty($id_lab)){
		$qry_hapus=mysql_query("delete from klaim_laboratorium where id_klaim='".$no_klaim."'");
		foreach($id_lab as $key=>$val){
			$sql_lab="insert into klaim_laboratorium(id_klaim,id_lab,tarif_ditanggung,tarif) 
				values ('$no_klaim','".$val."','".$harga_lab[$key]."','".$harga_lab_awal[$key]."')";
			$qry_lab=mysql_query($sql_lab);
		}
		}
		
		//insert elektromedik
		if(!empty($id_elektromedik)){
			$qry_hapus=mysql_query("delete from klaim_elektromedik where id_klaim='".$no_klaim."'");
			foreach($id_elektromedik as $key=>$val){
			$sql_elektromedik="insert into klaim_elektromedik(id_klaim,id_elektromedik,tarif_ditanggung,tarif) 
				values ('$no_klaim','".$val."','".$harga_elektromedik[$key]."','".$harga_elektromedik_awal[$key]."')";
			$qry_elektromedik=mysql_query($sql_elektromedik);
		}
		}
		
		//insert rehabilitasi
		if(!empty($id_rehabilitasi)){
			$qry_hapus=mysql_query("delete from klaim_rehabilitasi where id_klaim='".$no_klaim."'");
			foreach($id_rehabilitasi as $key=>$val){
			$sql_rehabilitasi="insert into klaim_rehabilitasi(id_klaim,id_rehabilitasi,tarif_ditanggung,tarif) 
				values ('$no_klaim','".$val."','".$harga_rehabilitasi[$key]."','".$harga_rehabilitasi_awal[$key]."')";
			$qry_rehabilitasi=mysql_query($sql_rehabilitasi);
		}
		}
		
		//insert radiologi
		if(!empty($id_radiologi)){
		$qry_hapus=mysql_query("delete from klaim_radiologi where id_klaim='".$no_klaim."'");
		foreach($id_radiologi as $key=>$val){
			$sql_radiologi="insert into klaim_radiologi(id_klaim,id_radiologi,tarif_ditanggung,tarif) 
				values ('$no_klaim','".$val."','".$harga_radiologi[$key]."','".$harga_radiologi_awal[$key]."')";
			$qry_radiologi=mysql_query($sql_radiologi);
		}
		}
		
		//update tarif
		$tarif=get_hitung_klaim($no_klaim);
		$tarif_ditanggung=$tarif['tarif_ditanggung'];
		$tarif_diminta=$tarif['tarif_diminta'];
		$sql_update_tarif="update klaim set total_diminta='$tarif_diminta', 
						total_ditanggung='$tarif_ditanggung' where id_klaim='$no_klaim'";
		$qry_update_tarif=mysql_query($sql_update_tarif);
	}
	
	$url_sukses='utama.php?module=mod_klaim';
	if($qry_klaim){
		echo "<meta http-equiv='refresh' content='0; url=$url_sukses'>";
		exit;
	}else{
		echo mysql_error();
	}
?>